<?php
// +----------------------------------------------------------------------
// | Iecms [ Make the most exquisite CMS ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009~2019 http://www.iemoo.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: iemoo <i@iemoo.com>
// +----------------------------------------------------------------------
// | DateTime: 2019/11/19 11:08
// +----------------------------------------------------------------------
namespace app\index\controller;

use app\common\model\Message as MessageModel;

use app\index\validate\Message as MessageValidate;
use think\exception\ValidateException;

use think\facade\Request;
use think\facade\View;
use think\facade\Config;

/**
 * 留言管理
 */
class Message extends Base
{
 
    /**
     * 留言管理
     * @return mixed
     */
    public function index()
    {
        $message_list = MessageModel::where('status',1)->select();
		View::assign('list',$message_list);

		View::assign('title','留言 - ');
		return View::fetch('index');
    }

  
    /**
     * 编辑留言
     * @param $id
     * @return mixed
     */
    public function add()
    {

		if (Request::isPost()) {

			$data = Request::only(['name', 'tel', 'mobile', 'email', 'message']);
			
			$data['ip'] = Request::ip();

            try {
				validate(MessageValidate::class)->check($data);
			} catch (ValidateException $e) {
				// 验证失败 输出错误信息
				$this->error($e->getError());
			}

			if (MessageModel::create($data)) {
				$this->success('留言成功',url('index/message/index'));
			} else {
				$this->error('留言失败');
			}


        }
		View::assign('title','提交留言 - ');
		return View::fetch('add');
    }

   


}